home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / Menu Fixer 1.0 Source / Menu fixer ƒ / MSG Shell ƒ / msg graphics.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-14  |  3.9 KB  |  164 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        msg graphics.c
  4.  
  5. Purpose:    This module handles the about box, about MSG box, main
  6.             window opening/closing/updating, and help windows
  7.             opening/closing/updating.
  8.  
  9.  
  10. Menu Fixer -=- synchronize menu IDs and menu resource IDs
  11. Copyright (C) 1993 Mark Pilgrim
  12.  
  13. This program is free software; you can redistribute it and/or modify
  14. it under the terms of the GNU General Public License as published by
  15. the Free Software Foundation; either version 2 of the License, or
  16. (at your option) any later version.
  17.  
  18. This program is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. GNU General Public License for more details.
  22.  
  23. You should have received a copy of the GNU General Public License
  24. along with this program in a file named "GNU General Public License".
  25. If not, write to the Free Software Foundation, 675 Mass Ave,
  26. Cambridge, MA 02139, USA.
  27.  
  28. \**********************************************************************/
  29.  
  30. #include "msg graphics.h"
  31. #include "msg dialogs.h"
  32. #include "msg environment.h"
  33. #include "msg menus.h"
  34. #include "msg error.h"
  35. #include "fix.h"
  36. #include "fix help.h"
  37.  
  38. Rect            gMainScreenBounds;
  39. GDHandle        gBiggestDevice;
  40. WindowPtr        gHelp[NUM_HELP];
  41. int                gHelpWidth;
  42. int                gHelpHeight;
  43.  
  44. void ShowInformation(void)
  45. {
  46.     DialogPtr    theDlog;
  47.     int            itemSelected = 0;
  48.     int            newleft;
  49.     int            newtop;
  50.     int            dlogID;
  51.     
  52.     if(GetWindowDepth() > 2)
  53.         dlogID = colorInfoDialog;
  54.     else
  55.         dlogID = bwInfoDialog;
  56.     
  57.     theDlog = GetNewDialog(dlogID, 0L, (WindowPtr)-1L);
  58.     newleft = gMainScreenBounds.left + (((gMainScreenBounds.right -
  59.                 gMainScreenBounds.left) - (theDlog->portRect.right -
  60.                 theDlog->portRect.left)) / 2);
  61.     newtop = gMainScreenBounds.top + (((gMainScreenBounds.bottom -
  62.                 gMainScreenBounds.top) - (theDlog->portRect.bottom -
  63.                 theDlog->portRect.top)) / 2);
  64.     if(newtop < 15)
  65.         newtop = 15;
  66.     MoveWindow(theDlog, newleft, newtop, TRUE);
  67.     ShowWindow(theDlog);
  68.     
  69.     while(itemSelected == 0)
  70.     {
  71.         ModalDialog(0L, &itemSelected);
  72.     }
  73.     HideWindow(theDlog);
  74.     DisposeDialog(theDlog);
  75. }
  76.  
  77. void GetMainScreenBounds(void)
  78. {
  79.     gMainScreenBounds = screenBits.bounds;
  80.     gMainScreenBounds.top += MBarHeight;
  81. }
  82.  
  83. int GetWindowDepth(void)
  84. {
  85.     return (gHasColorQD) ? (**(**GetMainDevice()).gdPMap).pixelSize : 1;
  86. }
  87.  
  88. void OpenHelpWindow(int whichHelp)
  89. {
  90.     Rect    helpRect;
  91.     
  92.     if (!(gHelp[whichHelp]))
  93.     {
  94.         helpRect.left=10+20*whichHelp;
  95.         helpRect.top=50+20*whichHelp;
  96.         helpRect.bottom=helpRect.top+gHelpHeight;
  97.         helpRect.right=helpRect.left+gHelpWidth;
  98.         
  99.         gHelp[whichHelp]=NewWindow(0L, &helpRect, "\p", TRUE, noGrowDocProc, 
  100.                                     (WindowPtr)-1L, TRUE, 0L);
  101.         SetHelpTitle(whichHelp);
  102.     }
  103.     
  104.     SetPort(gHelp[whichHelp]);
  105.     InvalRect(&((gHelp[whichHelp])->portRect));
  106. }
  107.  
  108. void SetHelpTitle(int whichHelp)
  109. {
  110.     Str255        name;
  111.     
  112.     GetItem(gHelpMenu, whichHelp + 1, name);
  113.     SetWTitle(gHelp[whichHelp], name);
  114. }
  115.  
  116. void UpdateHelp(int whichHelp)
  117. {
  118.     long        offRowBytes, sizeOfOff;
  119.     Ptr            myBits;
  120.     Rect        destRect, bRect;
  121.     int            err;
  122.     GrafPort    myGrafPort;
  123.     GrafPtr        myGrafPtr;
  124.     RgnHandle    oldClipRgn;
  125.     
  126.     SetPort(gHelp[whichHelp]);
  127.     
  128.     bRect = (gHelp[whichHelp])->portRect;
  129.     
  130.     myGrafPtr = &myGrafPort;
  131.     OpenPort(myGrafPtr);
  132.     
  133.     offRowBytes = ((gHelpWidth + 15) >> 4) << 1;
  134.     sizeOfOff = (long)(gHelpHeight) * offRowBytes;
  135.     OffsetRect(&bRect, -bRect.left, -bRect.top);
  136.     
  137.     myBits = NewPtr(sizeOfOff);
  138.     if(myBits == 0L)
  139.         ErrorString("\pThere is not enough memory.  ", "\p");
  140.     
  141.     myGrafPort.portBits.baseAddr = myBits;
  142.     myGrafPort.portBits.rowBytes = offRowBytes;
  143.     myGrafPort.portBits.bounds = bRect;
  144.     
  145.     myGrafPort.portRect = bRect;
  146.     
  147.     oldClipRgn = myGrafPort.clipRgn;
  148.     myGrafPort.clipRgn = (gHelp[whichHelp])->visRgn;
  149.     
  150.     SetPort(myGrafPtr);
  151.     
  152.     DrawHelp(whichHelp);
  153.     
  154.     SetPort(gHelp[whichHelp]);
  155.     
  156.     CopyBits(&(myGrafPtr->portBits),
  157.         &((gHelp[whichHelp])->portBits), &bRect, &bRect, 0, 0L);
  158.     
  159.     myGrafPort.clipRgn = oldClipRgn;
  160.     
  161.     ClosePort(myGrafPtr);
  162.     DisposPtr(myBits);
  163. }
  164.